package com.lingxin.gps.wap.command;

import com.lingxin.gps.sdk.GpsDeviceApi;
import com.pisces.core.Assert;
import com.pisces.core.BaseCommand;
import com.pisces.core.BizException;
import com.pisces.core.SimpleValidator;

/**
 *
 */
public class CUserModifyPwd extends BaseCommand {

	private String oldPassword;
	private String newPassword;
	private String confirmPassword;

	private Long uid;
	private String token;

	@Override
	public void init() throws Exception {
		oldPassword = getPara("oldPassword");
		Assert.notBlank(oldPassword, "旧密码不能为空");
		newPassword = getPara("newPassword");
		Assert.notBlank(newPassword, "新密码不能为空");
		Assert.notFalse(SimpleValidator.validatePassword(newPassword), "新密码只允许6~20位");

		confirmPassword = getPara("confirmPassword");
		Assert.notBlank(confirmPassword, "确认密码不能为空");
		if (!confirmPassword.equals(newPassword)) {
			throw new BizException("确认密码与新密码不一致");
		}

		uid = context.getAttr("uid");
		token = context.getAttr("token");
	}

	@Override
	public void doCommand() throws Exception {
		GpsDeviceApi.userModifyPwd(uid, token, oldPassword, newPassword, confirmPassword);
	}

}
